package cn.itcast.shop.product.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.itcast.shop.category.service.CategoryService;
import cn.itcast.shop.product.service.ProductService;
import cn.itcast.shop.product.vo.Product;
import cn.itcast.shop.utils.PageBean;

public class ProductAction extends ActionSupport implements ModelDriven<Product> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//
	private Product product = new Product();
	
	public Product getModel() {
		return product;
	}
	
	//接收一级分类cid
	private Integer cid;
	//接收二级分类id
	private Integer csid;
	//注入一级分类的Service
	private CategoryService categoryService;
	private ProductService productService ;
	
	public void setCid(Integer cid) {
		this.cid = cid;
	}
	
	/**
	 * 这样可以在页面的值栈中获取cid
	 * @return
	 */
	public int getCid(){
		return cid;
	}

	public void setCsid(Integer csid) {
		this.csid = csid;
	}
	
	public int getCsid() {
		return csid;
	}

	private int page;
	/**
	 * 当前页数
	 * @param page
	 */
	public void setPage(int page) {
		this.page = page;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	public void setProductService(ProductService productService) {
		this.productService = productService;
	}
	
	/**
	 * 根据商品的ID进行查询商品详细信息
	 * @return
	 */
	public String findByPid(){
		product= productService.findByPid(product.getPid());
		
		return "findByPid";
	}
	
	/**
	 * 根据一级分类的id查询商品
	 * @return
	 */
	public String findByCid(){
		//List<Category> cList = categorySerivce
		
		PageBean<Product> pageBean = productService.findByPageCid(cid,page);
		//将PageBean存入到值栈中：
		ActionContext.getContext().getValueStack().set("pageBean", pageBean);
		return "findByCid";
	}
	
	/**
	 * 根据二级分类的id查询商品
	 * @return
	 */
	public String findByCsid(){
		//List<Category> cList = categorySerivce
		
		//根据二级分类查询商品
		PageBean<Product> pageBean = productService.findByPageCsid(csid,page);
		//将PageBean存入到值栈中：
		ActionContext.getContext().getValueStack().set("pageBean", pageBean);
		return "findByCsid";
	}
	
	
}













